package com.core.service.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
    private static final String format = "dd-MMM-yyyy";
    private static SimpleDateFormat dateFormat;
    
    public static String getDay(Date date){
        dateFormat = new SimpleDateFormat("EEEE");
        return dateFormat.format(date);
    }
    
    public static String getDate(Date date){
        dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);
    }
    
    public static String getDate(Date date, String format){
        dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);
    }
    
    public static Date getDate(String date) {
        dateFormat = new SimpleDateFormat(format);
        try {
            return dateFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public static int getAge(Date birthDate){
        dateFormat = new SimpleDateFormat("yyyy");
        int currentYear = Integer.parseInt(dateFormat.format(new Date()));
        int birthYear = Integer.parseInt(dateFormat.format(birthDate));
        return currentYear-birthYear;
    }

}
